/*
 * Copyright (c) 2022. CloudStar.Co.Ltd. All rights reserved.
 */

package cn.com.config;


import cn.com.config.detector.CloudStarEncryptablePropertyDetector;
import cn.com.config.encryptor.DefaultEncryptor;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * jasypt配置
 */
@Configuration
public class JasyptConfiguration {

    /**
     * 自定义加密解密处理
     *
     * @param propertyDetector
     * @return
     */
    @Bean(name = "jasyptStringEncryptor")
    @ConditionalOnMissingBean
    public StringEncryptor stringEncryptor(CloudStarEncryptablePropertyDetector propertyDetector) {
        return new DefaultEncryptor(propertyDetector);
    }

    /**
     * 自定义探测器
     *
     * @return
     */
    @Bean(name = "encryptablePropertyDetector")
    @ConditionalOnMissingBean
    public CloudStarEncryptablePropertyDetector encryptablePropertyDetector() {
        return new CloudStarEncryptablePropertyDetector();
    }
}
